import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useSelectStore = defineStore(
  'select',
  () => {
    const select = ref([])
    const setEmptySelect = () => {
      select.value = []
    }
    const getSelect = computed(() => select.value)
    const setSelect = (newSelect) => {
      select.value = newSelect
    }
    const pushSelect = (newSelect) => {
      select.value.push(newSelect)
    }
    const removeSelect = (number) => {
      select.value.splice(number, 1)
    }
    const searchSelect = (key, value) => {
      return select.value.filter((item) => item[key] === value)
    }
    return { select, setEmptySelect, getSelect, pushSelect, removeSelect, searchSelect }
  },
  {
    persist: true
  }
)
